package com.csx.saas.merchant.tenant.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDateTime;
import com.csx.basic.base.entity.Entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import com.csx.saas.common.constant.DictionaryType;
import static com.csx.basic.utils.DateUtils.DEFAULT_DATE_TIME_FORMAT;
import com.csx.saas.merchant.tenant.enumeration.TenantChannelEnum;
import com.csx.saas.merchant.tenant.enumeration.TenantStateEnum;

import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE;

/**
 * <p>
 * 实体类
 * 企业
 * </p>
 *
 * @author ChenSongXin
 * @since 2021-03-15
 */
@Data
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("saas_tenant")
@ApiModel(value = "Tenant", description = "企业")
@AllArgsConstructor
public class Tenant extends Entity<Long> {

    private static final long serialVersionUID = 1L;

    /**
     * 租户登录账户
     */
    @ApiModelProperty(value = "租户登录账户")
    @NotEmpty(message = "租户登录账户不能为空")
    @Length(max = 50, message = "租户登录账户长度不能超过50")
    @TableField(value = "account", condition = LIKE)
    @Excel(name = "租户登录账户")
    private String account;

    /**
     * 租户登录密码
     */
    @ApiModelProperty(value = "租户登录密码")
    @Length(max = 64, message = "租户登录密码长度不能超过64")
    @TableField(value = "password", condition = LIKE)
    @Excel(name = "租户登录密码")
    private String password;

    /**
     * 渠道\n#{SYSTEM:平台开通;REGISTER:注册}
     */
    @ApiModelProperty(value = "渠道\n#{SYSTEM:平台开通;REGISTER:注册}")
    @TableField("channel")
    @Excel(name = "渠道\n#{SYSTEM:平台开通;REGISTER:注册}", replace = {"平台开通_SYSTEM", "注册_REGISTER",  "_null"})
    private TenantChannelEnum channel;

    /**
     * 租户开始时间
     */
    @ApiModelProperty(value = "租户开始时间")
    @TableField("start_time")
    @Excel(name = "租户开始时间", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime startTime;

    /**
     * 有效期 
     * 为空表示永久
     */
    @ApiModelProperty(value = "有效期")
    @TableField("expiration_time")
    @Excel(name = "有效期", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime expirationTime;

    /**
     * 企业简介
     */
    @ApiModelProperty(value = "企业简介")
    @Length(max = 255, message = "企业简介长度不能超过255")
    @TableField(value = "describe_", condition = LIKE)
    @Excel(name = "企业简介")
    private String describe;

    /**
     * 状态\n#{NORMAL:正常;LOCKED:锁定;EXPIRE:到期}
     */
    @ApiModelProperty(value = "状态\n#{NORMAL:正常;LOCKED:锁定;EXPIRE:到期}")
    @TableField("state")
    @Excel(name = "状态\n#{NORMAL:正常;LOCKED:锁定;EXPIRE:到期}", replace = {"正常_NORMAL", "锁定_LOCKED", "到期_EXPIRE",  "_null"})
    private TenantStateEnum state;

    /**
     * 版本编号
     */
    @ApiModelProperty(value = "版本编号")
    @Length(max = 20, message = "版本编号长度不能超过20")
    @TableField(value = "version_nbr", condition = LIKE)
    @Excel(name = "版本编号")
    private String versionNbr;


    @Builder
    public Tenant(Long id, LocalDateTime createTime, Long createdBy, LocalDateTime updateTime, Long updatedBy, 
                    String account, String password, TenantChannelEnum channel, LocalDateTime startTime, LocalDateTime expirationTime, 
                    String describe, TenantStateEnum state, String versionNbr) {
        this.id = id;
        this.createTime = createTime;
        this.createdBy = createdBy;
        this.updateTime = updateTime;
        this.updatedBy = updatedBy;
        this.account = account;
        this.password = password;
        this.channel = channel;
        this.startTime = startTime;
        this.expirationTime = expirationTime;
        this.describe = describe;
        this.state = state;
        this.versionNbr = versionNbr;
    }

}
